import 'dart:convert';
import 'package:flutter_dva/flutter_dva.dart';

class UserItem extends StateTmpl {
  String name;
  fromJson(Map json) {
    name = json["name"];
  }
  toJson() {
    return <String, dynamic> {
      "name": name,
    };
  }
}

class Request<T extends StateTmpl> extends StateTmpl {
  int code;
  String message;
  dynamic data;
  dynamic creator;

  Request(this.creator);

  void fromJson(Map json) {
    code = json["code"];
    message = json["message"];
    data = fromMapItem<T>(json["data"], () => creator());
  }

  Map toJson() {
    return <String,dynamic>{
      "code": code,
      "message": message,
      "data": toMapItem<T>(data),
    };
  }
}

void main() {
  String array = '{ "code": 200, "message": "", "data":[{"name":"刘红"}]}';
  Request<UserItem> obj = Request<UserItem>(()=> new UserItem());
  obj.fromJson(JsonDecoder().convert(array));
  String str = JsonEncoder().convert(obj);
  print(str);
}